﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;
using System.IO;

namespace DataBaseAccess
{
    class DataBaseConnection
    {
        private SQLiteConnection _conn;

        public DataBaseConnection()
        {
            DataBaseCreation();
        }

        private void DataBaseCreation()
        {
            _conn = new SQLiteConnection(String.Format("Data Source={0}{1};Version={2};foreign keys=true", 
                DbConstants.DbName, DbConstants.DbExtention, DbConstants.DbVersion));
        }

        public void ExecuteCommandNoReturn(List<string> SqlStatements)
        {
            _conn.Open(); 
            SQLiteTransaction myTrans = _conn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            SQLiteCommand sqCommand = _conn.CreateCommand();
            try
            {
                foreach (string sql in SqlStatements)
                {

                    sqCommand.CommandText = sql;
                    sqCommand.ExecuteNonQuery();
                }
                myTrans.Commit();
            }
            catch (Exception e)
            {
                myTrans.Rollback();
            }
            finally
            {
                sqCommand.Dispose();
                myTrans.Dispose();
                _conn.Close();
            }
        }
    }
}
